home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / dup.c < prev    next >
C/C++ Source or Header  |  1991-02-17  |  989b  |  47 lines

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. /* these will have to be adjusted at some time ++jrb */
  4. /* use these with caution, TOS 1.4 still has double re-direction bug! */
  5.  
  6. #include <stddef.h>
  7. #include <fcntl.h>
  8. #include <osbind.h>
  9. #include <errno.h>
  10. #include <mintbind.h>
  11. #include <unistd.h>
  12.  
  13. extern int __mint;
  14.  
  15. int dup(handle)
  16.     int handle;
  17. {
  18.     register int rv;
  19.  
  20.     if (__mint)
  21.         rv = Fcntl(handle, (long)0, F_DUPFD);
  22.     else
  23.         rv = Fdup(handle);
  24.  
  25.     if(rv < (__SMALLEST_VALID_HANDLE)) {
  26.         errno = -rv; rv = -1;
  27.     } else if (__OPEN_INDEX(rv) < __NHANDLES) {
  28.         __open_stat[__OPEN_INDEX(rv)] =
  29.         __open_stat[__OPEN_INDEX(handle)];
  30.     }
  31.     return(rv);
  32. }
  33.  
  34. int dup2(handle1, handle2)
  35.     int handle1, handle2;
  36. {
  37.     int rv;
  38.  
  39.     close(handle2);
  40.     if ((rv = Fforce(handle2, handle1)) < 0)
  41.         errno = -rv;
  42.     else if (__OPEN_INDEX(handle2) < __NHANDLES)
  43.         __open_stat[__OPEN_INDEX(handle2)] =
  44.         __open_stat[__OPEN_INDEX(handle1)];
  45.     return (rv < 0) ? -1 : handle2;
  46. }
  47.